package Thread.Thread6;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Demo {
    //目标，有100份礼品，小红小明同时发送，当剩下的礼品小于10份的时候则不在送出
    //利用多线程模拟该过程并将线程的名称打印出来，并最后在控制台分别打印小红，小明各自送出多少礼物
    public static void main(String[] args) throws InterruptedException {
    //拿100份礼品放到程序中
        List<String> gift = new ArrayList<>();
        for (int i = 0;i<100;i++){
            String[] name = {"口红","包包","鲜花","剃须刀","皮带","手表"};
            Random r = new Random();
            gift.add(name[r.nextInt(name.length)]+(i+1));


        }
        System.out.println(gift);
        // 定义线程类，创建线程对象，去集合中拿礼物给别人
        SendThraed xm1 = new SendThraed(gift,"小明");
        xm1.start();
        SendThraed xm2 = new SendThraed(gift, "小红");
        xm2.start();

        xm1.join();
        xm2.join();
        System.out.println(xm1.getCount());

        System.out.println(xm2.getCount());

    }

}
